<%@page import="support.*, java.util.*" %>
<HTML>
<HEAD><TITLE>Discipline Analytics Page</TITLE></HEAD>
<BODY>
Choose the specialization you want to check : 
<p>
 <%-- Import the java.sql package --%>
 <%@ page import="java.sql.*"%>
 <%-- -------- Open Connection Code -------- --%>
 <%
            
   Connection conn = null;
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
    // Registering Postgresql JDBC driver with the DriverManager
    Class.forName("org.postgresql.Driver");
   // Open a connection to the database using DriverManager
   conn = DriverManager.getConnection(
     "jdbc:postgresql://localhost/admissions?" +
        "user=postgres&password=27428572");
 %>
<%
 // Begin transaction
      conn.setAutoCommit(false);
 %>
<%
Statement stmt = conn.createStatement();
Statement stmt2 = conn.createStatement();
support s = new support();
String path4 = config.getServletContext().getRealPath("majors.txt");
Vector major = s.getMajors(path4);
ResultSet majors = stmt.executeQuery("SELECT name FROM disciplines");

while (majors.next())
{
out.println(majors.getString(1)+ " : ");
ResultSet specId = stmt2.executeQuery("SELECT id FROM disciplines WHERE name = '"+majors.getString(1)+"'");
int count = 0;
specId.next();
ResultSet deId = stmt2.executeQuery("SELECT id FROM degrees WHERE name = '"+specId.getInt(1)+"'");
while(deId.next())
	count++;
out.println("             ");
%>
<a href="application.jsp?discipline=<%=majors.getString(1)%>"><%=count%></a>
<%
out.println("<br>");
}
//out.println("Other Discipline : ");
//ResultSet otherId = stmt.executeQuery("SELECT id FROM disciplines WHERE name != 'Computer Science');
//<a href="application.jsp?discipline=other"><
 }

			catch (SQLException e){
				throw new RuntimeException(e);
			}

finally{
		if(rs != null){
					try{ 
						rs.close();
					}catch (SQLException e){ }
					rs = null;
				}
				if(pstmt != null){
					try{
						pstmt.close();
					}catch(SQLException e){}
					pstmt = null;
				}
				if(conn != null){
					try{
						conn.close();
					}catch (SQLException e) { }
					conn = null;
				}

		}

%>

</SELECT>
</FORM>
</BODY>
</HTML>


